package com.jcp.daoimp;


import java.util.Date;
import java.util.List;

import com.jcp.dao.NoticesDao;
import com.jcp.entity.Notices;
import com.jcp.util.DBUtil;
import com.jcp.util.PageData;
/**
 * 公告管理的Dao
 * @author 朱耿封
 *
 */
public class NoticesDaoImp implements NoticesDao {
	/**
	 * 公告管理的添加功能
	 * 返回值：boolean
	 * 参数：公告类的实体类
	 */
	@Override
	public boolean addNotices(Notices notices) {
		String sql = "insert into notices(notContent,notLevel,notTime)values(?,?,NOW())";//添加功能语句
		return DBUtil.exUpdate(sql,notices.getNotContent(),notices.getNotLevel())>0;//操作成功返回大于1的数
	}
	/**
	 * 公告管理的删除功能
	 * 返回值：boolean
	 * 参数：公告ID;
	 */
	@Override
	public boolean delNotices(int NoticesId) {
		// TODO Auto-generated method stub
		String sql = "delete from notices where notId = ? ";//删除功能语句
		return DBUtil.exUpdate(sql, NoticesId)>0;//操作成功返回大于1的数
	}
	/**
	 * 公告管理的全查询功能
	 * 返回值：List<Notices>
	 * 参数：notid（公告编号）
	 */
	@Override
	public List<Notices> selNotices(String notContent,int notid) {
		String sql = "select * from notices where notContent like ?";//查询语句
		List<Notices> list = DBUtil.exQuery(sql,Notices.class,"%"+notContent+"%");//查询成功返回集合
		
		return list;
	}
	/**
	 * 公告管理的更新功能
	 * 返回值：boolean
	 * 参数：Notices�?
	 */
	@Override
	public boolean updsNotices(Notices notices) {
		String sql = "update notices set notContent=?,notTime=? where notId = ?";//更新功能语句
		return DBUtil.exUpdate(sql, notices.getNotContent(),notices.getNotTime(),notices.getNotId())>0;//操作成功返回大于1的数
	}

	@Override
	/**
	 * 查看部门公告的方法
	 */
	public List<Notices> selNoticesByNotLevel(int notLevel) {
		// TODO Auto-generated method stub
		String sql="SELECT * from notices where notLevel=? ORDER BY notTime DESC ";
		List<Notices> list =DBUtil.exQuery(sql, Notices.class, notLevel);
		return list;
	}

	@Override
	public PageData<Notices> selNoticesPage(int curr, int limit1,String notContent) {
		String sql = "select * from notices where notContent like ? and notLevel=0";
		PageData<Notices> list = DBUtil.exQueryByPage(sql, Notices.class, curr, limit1,"%"+notContent+"%");
		// TODO Auto-generated method stub
		return list;
	}
	
	@Override
	/**
	 * 查看前三条公司公告的方法
	 */
	public List<Notices> selCompanyNotices() {
		// TODO Auto-generated method stub
		String sql="SELECT * from notices where notLevel=0 ORDER BY notTime DESC LIMIT 0,3";
		List<Notices> list = DBUtil.exQuery(sql, Notices.class);

		return list;
	}
}
